package com.fengcone.spring.boot;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {

	@RequestMapping("/index")
	public String helloWorld() {
		return "Hello World 试试中文";
	}

	@RequestMapping("/download.rar")
	public void download(HttpServletResponse response) throws IOException {
		File file = new File("D://迅雷下载.rar");

		FileInputStream fileInputStream = new FileInputStream(file);
		byte[] buffer = new byte[1024 * 1024 * 8];

		int read = fileInputStream.read(buffer);
		while (read != -1) {
			response.getOutputStream().write(buffer);
			read = fileInputStream.read(buffer);
		}
		fileInputStream.close();
	}
}
